package mamikeji.liaowa.ui.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;

import java.util.ArrayList;
import java.util.List;

import mamikeji.liaowa.R;
import mamikeji.liaowa.bean.FriendCircleInfoBean;

/**
 * Created by 廉冲-android开发 on 2017/6/15.
 */
public class CircleCommentAdapter extends BaseAdapter {
    List<FriendCircleInfoBean.FriendchatEntity> mList = new ArrayList<>();
    LayoutInflater inflater;
    Context context;

    public CircleCommentAdapter() {
    }

    public CircleCommentAdapter(List<FriendCircleInfoBean.FriendchatEntity> mList, Context context) {
        this.mList = mList;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    public void setList(List<FriendCircleInfoBean.FriendchatEntity> mList) {
        this.mList = mList;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public FriendCircleInfoBean.FriendchatEntity getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_circle_details_comment, null);
            viewHolder = new ViewHolder();

            viewHolder.textView_circle_details_username = (TextView) convertView.findViewById(R.id.textView_circle_details_username);
            viewHolder.textView_circle_details_content = (TextView) convertView.findViewById(R.id.textView_circle_details_content);
            viewHolder.textView_details_recomment_recommentusername = (TextView) convertView.findViewById(R.id.textView_details_recomment_recommentusername);
            viewHolder.linearLayout_details_comment = (LinearLayout) convertView.findViewById(R.id.linearLayout_details_comment);
            viewHolder.imageView_circle_details_userimg = (SimpleDraweeView) convertView.findViewById(R.id.imageView_circle_details_userimg);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        FriendCircleInfoBean.FriendchatEntity dataEntity = getItem(position);
        viewHolder.textView_circle_details_content.setText(dataEntity.getContent());
        if (dataEntity.getRusercode().equals("")||dataEntity.getRusercode() == null){
            viewHolder.linearLayout_details_comment.setVisibility(View.GONE);
            viewHolder.textView_circle_details_username.setText(dataEntity.getCname());
        }else {
            viewHolder.linearLayout_details_comment.setVisibility(View.VISIBLE);
            viewHolder.textView_details_recomment_recommentusername.setText(dataEntity.getCname());
            viewHolder.textView_circle_details_username.setText(dataEntity.getRname());
        }
        viewHolder.imageView_circle_details_userimg.setImageURI(Uri.parse(dataEntity.getAvatar()));
        return convertView;
    }

    public class ViewHolder {
        TextView textView_circle_details_username;
        TextView textView_circle_details_content;
        TextView textView_details_recomment_recommentusername;
        LinearLayout linearLayout_details_comment;
        SimpleDraweeView imageView_circle_details_userimg;
    }
}
